#include <QtGui>

#include "searchdialog.h"

SearchDialog::SearchDialog(const QString &title, QWidget *parent)
    : QDialog(parent)
{
    searchLabel = new QLabel(tr("Search:"));
    searchEdit = new QLineEdit;
    buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
                                     | QDialogButtonBox::Cancel);

    connect(buttonBox, SIGNAL(accepted()), this, SLOT(verify()));
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));

    QGridLayout *mainLayout = new QGridLayout;
    mainLayout->addWidget(searchLabel, 0, 0);
    mainLayout->addWidget(searchEdit, 0, 1);
    mainLayout->addWidget(buttonBox, 0,2);
    setLayout(mainLayout);

    setWindowTitle(title);
}

QString SearchDialog::searchText() const
{
    return searchEdit->text();
}

void SearchDialog::verify()
{
    if (!searchEdit->text().isEmpty()) {
        accept();
        return;
    }

    QMessageBox::StandardButton answer;
    answer = QMessageBox::warning(this, tr("Incomplete Form"),
        tr("No search keyword was entered.\n"
           "Do you want to discard it?"),
        QMessageBox::Yes | QMessageBox::No);

    if (answer == QMessageBox::Yes)
        reject();
}


